package token

import (
	"fmt"

	"github.com/pkoukk/tiktoken-go"
)

func EnCode(content string, model string) []int {
	tkm, err := tiktoken.EncodingForModel(model)
	if err != nil {
		err = fmt.Errorf("getEncoding: %v", err)
		return nil
	}

	// encode
	return tkm.Encode(content, nil, nil)
}

func Decode(ids []int, model string) string {
	tkm, err := tiktoken.EncodingForModel(model)
	if err != nil {
		return ""
	}
	return tkm.Decode(ids)
}
